package com.youfan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.youfan.entity.ProductattributeDict;
import com.youfan.mapper.ProductAttrdictMapper;
import com.youfan.page.CommonPage;
import com.youfan.service.ProductAttrDictService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Service
public class ProductattrDictServiceImpl extends ServiceImpl<ProductAttrdictMapper, ProductattributeDict> implements ProductAttrDictService {

    @Autowired
    private ProductAttrdictMapper productAttrdictMapper;




    @Override
    public int insertOne(ProductattributeDict youfanproductattributeDict) {
        youfanproductattributeDict.setCreateTime(new Date());
        return productAttrdictMapper.insert(youfanproductattributeDict);
    }

    @Override
    public CommonPage<ProductattributeDict> queryByCondtion(ProductattributeDict youfanproductattributeDict) {
        PageHelper.startPage(youfanproductattributeDict.getPageNum(),youfanproductattributeDict.getPageSize());
        QueryWrapper queryWrapper = new QueryWrapper();

        if(youfanproductattributeDict.getCategorytype()!=null){
            queryWrapper.eq("categorytype", youfanproductattributeDict.getCategorytype());
        }
        if(StringUtils.isNotBlank(youfanproductattributeDict.getName())){
            queryWrapper.like("name",youfanproductattributeDict.getName());
        }

        if(youfanproductattributeDict.getSelectType()!=null){
            queryWrapper.eq("select_type",youfanproductattributeDict.getSelectType());
        }

        if(youfanproductattributeDict.getInputType()!=null){
            queryWrapper.eq("input_type",youfanproductattributeDict.getInputType());
        }
        if(youfanproductattributeDict.getType()!=null){
            queryWrapper.eq("type",youfanproductattributeDict.getType());
        }


        List<ProductattributeDict> list = productAttrdictMapper.selectList(queryWrapper);


        return CommonPage.restPage(list);
    }

    @Override
    public ProductattributeDict findByid(ProductattributeDict youfanproductattributeDict) {
        return productAttrdictMapper.selectById(youfanproductattributeDict.getId());
    }

    @Override
    public int updateOne(ProductattributeDict youfanproductattributeDict) {
        return productAttrdictMapper.updateById(youfanproductattributeDict);
    }
}
